package com.swf.common.exception;

public class WebException extends Exception {

	private static final long serialVersionUID = -4155643151065834009L;
	private String errorCode;
	private String showMessage;
	private Throwable cause;
	
	public WebException() {
	}

	public WebException(String message) {
		super(message);
	}

	public WebException(String errorCode, String message) {
		super(message);
		this.errorCode = errorCode;
	}

	public WebException(String message, Throwable cause) {
		super(message,cause);
		this.cause = cause;
	}

	public WebException(String errorCode, String message, Throwable cause) {
		super(message, cause);
		this.showMessage = message;
		this.cause = cause;
	}
	
	
	
	public WebException(Throwable cause) {
		super(cause);
		this.cause = cause;
	}

	public String getMessage() {
		String msg = super.getMessage();
		String causeMsg = null;
		if (this.cause != null){
			causeMsg = this.cause.getMessage();
		}
		if (msg != null){
			if (causeMsg !=null){
				return msg + " caused by: " + causeMsg;
			}
			return msg;
		}
		return causeMsg;
	}
	
	public String getErrorCode() {
		return errorCode;
	}

	public void setErrorCode(String errorCode) {
		this.errorCode = errorCode;
	}

	public String getShowMessage() {
		return showMessage;
	}

	public void setShowMessage(String showMessage) {
		this.showMessage = showMessage;
	}

	@Override
	public String toString() {
		if (this.cause == null){
			return super.toString();
		}
		return super.toString()+" cause: " + this.cause.toString(); 
	}
	
	
}
